1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.process;
9
10 import com.tirsen.angkor.Application;
11 import com.tirsen.angkor.RenderContext;
12 import com.tirsen.angkor.event.EventQueue;
13
14 import java.util.Iterator;
15
16 /***
17 * <!-- $Id: EventValve.java,v 1.4 2002/10/13 13:37:26 tirsen Exp $ -->
18 * <!-- $Author: tirsen $ -->
19 *
20 * @author Jon Tirs´n (tirsen@users.sourceforge.net)
21 * @version $Revision: 1.4 $
22 */
23 public class EventValve implements Valve
24 {
25 public static final ExecuteContext.Attribute CurrentEventAttribute = new ExecuteContext.Attribute("CurrentEvent");
26
27 /***
28 * Create a sub-pipeline which is executed for each event. This pipeline catches warnings (according to
29 * {@link Application.isWarning(Throwable)} but not fatal errors. If a warnings occurs event processing continues.
30 */
31 private Pipeline createEventPipeline()
32 {
33 Pipeline pipeline = new DefaultPipeline();
34 pipeline.addValve(new ProcessEventValve());
35 return pipeline;
36 }
37
38 public static class ProcessEventValve implements Valve
39 {
40 public void execute(ExecuteContext exec) throws Exception
41 {
42 EventQueue.QueuedEvent event = (EventQueue.QueuedEvent) exec.getAttribute(CurrentEventAttribute);
43 Application application = (Application) exec.getAttribute(ExecuteContext.ApplicationAttribute);
44 event.send(application);
45 }
46 }
47
48 public void execute(ExecuteContext exec) throws Exception
49 {
50 Application application = (Application) exec.getAttribute(ExecuteContext.ApplicationAttribute);
51 RenderContext renderContext = (RenderContext) exec.getAttribute(ExecuteContext.RenderContextAttribute);
52 // events no longer need to be postponed until later, but can instead be processed immediately
53 renderContext.getEventQueue().setPostponeEvents(false);
54 Pipeline eventPipeline = createEventPipeline();
55 Iterator it = renderContext.getEventQueue().iterateEvents();
56 while (it.hasNext())
57 {
58 EventQueue.QueuedEvent event = (EventQueue.QueuedEvent) it.next();
59 ExecuteContext subExec = eventPipeline.createExecuteContext(renderContext);
60 subExec.setAttribute(CurrentEventAttribute, event);
61 // bind current view to get warnings associated with the source of the event
62 subExec.setAttribute(ExecuteContext.CurrentViewAttribute, event.getEvent().getSource());
63 eventPipeline.execute(subExec);
64 }
65 exec.executeNext();
66 // restore to the next time
67 renderContext.getEventQueue().setPostponeEvents(true);
68 }
69 }
This page was automatically generated by Maven